import { useState } from 'react';
import { PaginationResponse } from '@datorama/akita';

import { makeFacade, TwMessagesFacade } from '@/facade/twMessageFacade';
import { useObservable } from '@/utils/rxHelpers';
import { MessageItem } from '@/models/Message';

export type TwEntityHookTuple = [TwMessagesFacade, PaginationResponse<MessageItem>];

//需要在页面用到的变量都在这里hook，主要用于简化页面调用逻辑和代码
export function useTwEntityFacade(groupId: string): TwEntityHookTuple {
  const [twEntityFacade] = useState(() => makeFacade(groupId)); //默认返回访问过的房间列表
  
  // const [filter] = useObservable(twEntityFacade.filter$, VISIBILITY_FILTER.SHOW_ALL);
  const [pagination] = useObservable(twEntityFacade.pagination$, {} as PaginationResponse<MessageItem>);

  return [twEntityFacade, pagination];
}
